#include "SMPPAlertNotification.hpp"

using namespace smpp::pdu;

AlertNotification::AlertNotification(const Header &nHeader,
const quint8 nSourceAddrTON,const quint8 nSourceAddrNPI, 
const CoctetString &nSourceAddr,const quint8 nESMEAddrTON, 
quint8 nESMEAddrNPI,const CoctetString &nESMEAddr,
const MsAvailabilityStatus *nMsAvailabilityStatus):
Header(nHeader),
_SourceAddrTON(nSourceAddrTON),
_SourceAddrNPI(nSourceAddrNPI),
_SourceAddr(nSourceAddr),
_ESMEAddrTON(nESMEAddrTON),
_ESMEAddrNPI(nESMEAddrNPI),
_ESMEAddr(nESMEAddr),
_MsAvailabilityStatus(0){
	if(nMsAvailabilityStatus)
		_MsAvailabilityStatus = 
		new MsAvailabilityStatus(*nMsAvailabilityStatus);
}

AlertNotification::AlertNotification(
const AlertNotification &nAlertNotification):
Header(nAlertNotification),
_SourceAddrTON(nAlertNotification.getSourceAddrTON()),
_SourceAddrNPI(nAlertNotification.getSourceAddrNPI()),
_SourceAddr(nAlertNotification.getSourceAddr()),
_ESMEAddrTON(nAlertNotification.getESMEAddrTON()),
_ESMEAddrNPI(nAlertNotification.getESMEAddrNPI()),
_ESMEAddr(nAlertNotification.getESMEAddr()),
_MsAvailabilityStatus(0){
	if(nAlertNotification.getMsAvailabilityStatus())
		_MsAvailabilityStatus = new MsAvailabilityStatus(
		*nAlertNotification.getMsAvailabilityStatus());
}

AlertNotification::~AlertNotification(){
	if(_MsAvailabilityStatus)
		delete _MsAvailabilityStatus;
}

bool AlertNotification::operator ==(
	const AlertNotification &nAlertNotification) const{
	bool condition(
		(_SourceAddrTON == nAlertNotification.getSourceAddrTON())&&
		(_SourceAddrNPI == nAlertNotification.getSourceAddrNPI())&&
		(_SourceAddr == nAlertNotification.getSourceAddr())&&
		(_ESMEAddrTON == nAlertNotification.getESMEAddrTON())&&
		(_ESMEAddrNPI == nAlertNotification.getESMEAddrNPI())&&
		(_ESMEAddr == nAlertNotification.getESMEAddr())
	);
	if(condition == false)
		return false;
	return (*_MsAvailabilityStatus ==
			*nAlertNotification.getMsAvailabilityStatus());
}

bool AlertNotification::operator !=(
	const AlertNotification &nAlertNotification) const{
	return !operator ==(nAlertNotification);
}

AlertNotification &AlertNotification::operator =(
	const AlertNotification &nAlertNotification){
	if(*this == nAlertNotification)
		return *this;
	_SourceAddrTON = nAlertNotification.getSourceAddrTON();
	_SourceAddrNPI = nAlertNotification.getSourceAddrNPI();
	_SourceAddr = nAlertNotification.getSourceAddr();
	_ESMEAddrTON = nAlertNotification.getESMEAddrTON();
	_ESMEAddrNPI = nAlertNotification.getESMEAddrNPI();
	_ESMEAddr = nAlertNotification.getESMEAddr();
	*_MsAvailabilityStatus =
	*nAlertNotification.getMsAvailabilityStatus();
	return *this;
}

void AlertNotification::setSourceAddrTON(const quint8 nSourceAddrTON){
	_SourceAddrTON = nSourceAddrTON;
}

const quint8 AlertNotification::getSourceAddrTON() const{
	return _SourceAddrTON;
}

void AlertNotification::setSourceAddrNPI(const quint8 nSourceAddrNPI){
	_SourceAddrNPI = nSourceAddrNPI;
}

const quint8 AlertNotification::getSourceAddrNPI() const{
	return _SourceAddrNPI;
}

void AlertNotification::setSourceAddr(const CoctetString& sSourceAddr){
	_SourceAddr = sSourceAddr;
}

const CoctetString &AlertNotification::getSourceAddr() const{
	return _SourceAddr;
}

void AlertNotification::setESMEAddrTON(const quint8 nESMEAddrTON){
	_ESMEAddrTON = nESMEAddrTON;
}

const quint8 AlertNotification::getESMEAddrTON() const{
	return _ESMEAddrTON;
}

void AlertNotification::setESMEAddrNPI(const quint8 nESMEAddrNPI){
	_ESMEAddrNPI = nESMEAddrNPI;
}

const quint8 AlertNotification::getESMEAddrNPI() const{
	return _ESMEAddrNPI;
}

void AlertNotification::setESMEAddr(const CoctetString &sESMEAddr){
	_ESMEAddr = sESMEAddr;
}

const CoctetString &AlertNotification::getESMEAddr() const{
	return _ESMEAddr;
}

void AlertNotification::setMsAvailabilityStatus(
	const MsAvailabilityStatus *nMsAvailabilityStatus){
	if(_MsAvailabilityStatus){
		delete _MsAvailabilityStatus;
		_MsAvailabilityStatus = 0;
	}
	if(nMsAvailabilityStatus)
		_MsAvailabilityStatus = 
		new MsAvailabilityStatus(*nMsAvailabilityStatus);
}

const MsAvailabilityStatus *AlertNotification::
	getMsAvailabilityStatus() const{
		return _MsAvailabilityStatus;
}

void AlertNotification::calcCommandLength(){
	_CommandLength = 20 + _SourceAddr.size() + _ESMEAddr.size();
	if(_MsAvailabilityStatus)
		_CommandLength += 5;
}
